package org.example.zuoye.api;

import org.example.zuoye.entity.Patient;
import org.example.zuoye.entity.Result;
import org.example.zuoye.entity.Schedules;
import org.example.zuoye.service.PatientService;

import org.example.zuoye.service.SchedulesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author xinchen
 * @Date: 2024/08/13/ 11:43
 * @Description
 */
@RestController
@RequestMapping(value = "/api/v1/schedules")
public class SchedulesApi {

    @Autowired
    private SchedulesService schedulesService;

    /**
     *  select
     */
    @GetMapping
    public Result search(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit,
                         Schedules schedules){
        return Result.success(schedulesService.search(page, limit, schedules));
    }
    // /**
    //  * remove
    //  */
    @DeleteMapping
    public Result remove(@RequestBody Integer[] ids){
        try {
            schedulesService.remove(ids);
            return Result.success();
        }catch (Exception e){
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }
    /**
     *  add
     */
    @PostMapping
    public Result add(@RequestBody Schedules shedules){
        try {
            schedulesService.add(shedules);
            return Result.success();
        }catch (Exception e){
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }
    /**
     *  edit
     */
    @PutMapping
    public Result edit(@RequestBody Schedules shedules){
        try {
            schedulesService.edit(shedules);
            return Result.success();
        }
        catch (Exception e){
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }
}
